package cn.zh.npro.Adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.squareup.picasso.Picasso;

import java.util.ArrayList;

import cn.zh.npro.Item.OdItem;
import cn.zh.npro.R;

/**
 * Created by WYN on 2018/3/6 0006.
 */

public class OgAdapter extends BaseAdapter {
    Context context;
    ArrayList<OdItem> arrayList;
    LayoutInflater inflater;

    public OgAdapter(Context context,ArrayList<OdItem> arrayList){
        this.context=context;
        this.arrayList=arrayList;
        inflater=LayoutInflater.from(context);
        }

    @Override
    public int getCount() {
        return arrayList.size();
    }

    @Override
    public Object getItem(int i) {
        return arrayList.get(i);
    }

    @Override
    public long getItemId(int i) {
        return i;
    }

    @Override
    public View getView(int i, View view, ViewGroup viewGroup) {
        Holder holder=null;
        if (null==view){
            holder=new Holder();
            view=inflater.inflate(R.layout.og_layout,null,false);
            holder.ogimage=view.findViewById(R.id.ogimage);
            holder.txtname=view.findViewById(R.id.txtname);
            holder.uint=view.findViewById(R.id.uint);
            holder.pritxt=view.findViewById(R.id.pritxt);
            holder.sptxt=view.findViewById(R.id.sptxt);
            holder.numtxt=view.findViewById(R.id.numtxt);
            view.setTag(holder);
         }else {
            holder= (Holder) view.getTag();
          }
        Picasso.with(context).load(arrayList.get(i).getIndexURL()).error(R.mipmap.noimage).into(holder.ogimage);
        holder.txtname.setText(arrayList.get(i).getGoodsName());
        holder.sptxt.setText(arrayList.get(i).getSpecName());
        holder.uint.setText("单位"+arrayList.get(i).getUnit2());
        holder.pritxt.setText("¥"+arrayList.get(i).getSellPrice());
        holder.numtxt.setText(arrayList.get(i).getSellCount()+"件");

        return view;

        }






    public class Holder{
      ImageView ogimage;
      TextView txtname,uint,pritxt,numtxt,sptxt;
    }



}
